Ext.define('PJ.view.registrationmanagement.List', {
    extend: 'AM.default.DefaultList',
    requires: ['AM.default.DefaultDateField', 
               'AM.default.DateTime', 
               'AM.default.DefaultSearchForm',
               'AM.default.jsonp.DefaultLoadJsonp',//jsonp加载数据
               'PJ.view.registrationmanagement.ApplicationAuditList',//报名审核
               'PJ.view.registrationmanagement.ChooseUserFrame',//报名调整
               'PJ.view.quotamanagement.AdjustTheQuotaList',
               'PJ.view.registrationmanagement.ViewExperienceList'//已上传心得人员列表
               ],
               
    //报名管理列表--中组部，部委
               
    initComponent: function(){
        var me = this;
        me.columns = [{
            header: '培训班编号',
            dataIndex: 'tc.class_Num',
            minWidth: 110,
    		renderer: function(value, meta, record){
    			meta.style = "white-space:normal;cursor: pointer;color:blue;";
    			meta.tdAttr = "data-qtip='" + value + "' classId=" + record.get("classId");
    			return value;
    		},
    		listeners: {
    			click: function(g, clm){
      				var classId = clm.getAttribute("classId");
      				win = Ext.create('PJ.view.trainingmanagement.Look', {
      					title: "查看培训班",
      					flag:4,
      					grid: me,
      					isDisable:false,
      					isReadOnly:true,
      					classId:classId,
      					isHideExpectTime: false
      				}).show();
      				var actionName = "load";
      				if(gj_onlineLearning_constant.loadType == "jsonp"){
      					actionName = "loadJsonp";
      				}
      				win.down("form").getForm().doAction(actionName,{
      					url:me.store.preUpdateUrl,
      					params:{
      						classId: classId
      					},
      					success:function(f,action){
//      						var data = action.response.responseText;
//      	        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
//      	        			var form = win.down('form');	 
//      	        			var baseForm = form.getForm();
//      	        			baseForm.findField("classNum").setValue(json.data.classNum);
//      	        			baseForm.findField("classNum_").setValue(json.data.classNum);
      					}
      				});
      			}
    		}
        },{
            header: '培训班名称',
            dataIndex: 'tc.class_Name',
            flex: 1,
            minWidth: 110,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '主办单位',
            dataIndex: 'tc.sponsor_Name',
            width: 90,
            renderer: function(value, meta, record){
            	if (value == "西城区") {
      				value = "西城区委组织部";
      			}
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '培训班类型',
            dataIndex: 'bb1.DATA_CODE',
            width: 90,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '开班时间',
            dataIndex: 'tc.begin_Date',
            width: 110,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        },{
            header: '结业时间',
            dataIndex: 'tc.end_Date',
            width: 90,
            renderer: function(value, meta, record){
            	meta.tdAttr = "data-qtip='" + value + "'";
            	return value;
            }
        }, {
            header: '已报/通过',
            dataIndex: 'reportedNumStr',
            width: 115,
            sortable: false,
            renderer: function(value, meta, record){
            	meta.style = record.get("reportedNum") == 0 ? "0/0" : "white-space:normal;cursor: pointer;color:blue;";
            	meta.tdAttr = "classID='" + record.get("classId") + "'reportedNum='" + record.get("reportedNumStr") + 
            	"'className='" + record.get("tc.class_Name") + //班级名称
            	"'beginDate='" + record.get("tc.begin_Date")+ "'endDate='" + record.get("tc.end_Date")+ "'";//开结班时间
            	var reportNum = record.get("reportedNumStr");
            	//var planCount = record.get("planCount");
            	//var valueStr = Number(planCount) - Number(reportNum);
            	//var kbCount = record.get("kbCount");
            	//var valueStr = record.get("planCount")=="-1"? '不限' : record.get("planCount");
//				return reportNum + "/" + kbCount;
				return reportNum;
			},
			listeners: {
				click: function(g, clm){
					if(clm.getAttribute("reportedNum") != "0/0"){
						win = Ext.create('PJ.view.unitregistrationmanagement.ViewSignupStatusFrameButton',{
				    		title: "查看报名人员",
				    		grid: me,
				    		clickSource:1,
				    		classId:clm.getAttribute("classID"),
				    		className:clm.getAttribute("className"),
				    		beginDate: clm.getAttribute("beginDate"),
				    		endDate: clm.getAttribute("endDate")
				    	}).show();
						var actionName = "load";//默认使用非JSONP的加载方法名“load”
						if(gj_onlineLearning_constant.loadType=="jsonp") {//根据模块的全局变量设置是否使用JSONP的方式请求数据
							actionName= "loadJsonp";
						}
						win.down('form').getForm().doAction(actionName,{//使用doAction(action,{options})；方式加载数据
							url: me.store.configurationUrl,
							params: {
								classId: clm.getAttribute("classID")//培训班ID
							},
							success:function(form,action){
								var data = action.response.responseText;
			        			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
								var dateStar = json.data.beginDateStr;//举办时间（开始）
								var dateEnd = json.data.endDateStr;//举办时间（截止）
								var form = win.down('form');	 
								var baseForm = form.getForm();
								baseForm.findField("learnTime").setValue(dateStar + ' 至 ' + dateEnd);
							}
						});
					}
				}
			}
        },/* {
            header: '审核状态',
            dataIndex: 't.auditState',
            width: 85,
            renderer: function(value, meta, record){
                if(value==2){
              	   return "审核未通过";
                 }else if(value==1){
              	   return "审核通过";
                 }else if(value==3){
              	   return "未审核";
                 }
              }
        },*/{
            header: '班级状态',
            dataIndex: 'tc.open_State',
            renderer: function(v, meta, record){
            	if(record.get("tc.publish_State") == 2){
            		return '未开班';
            	}else{
            		if (v == 3) {
                        return '<span style="color:red;">' + '已结班' + '</span>';
                    }
                    else if(v == 1) {
                        return '<span style="color:green;">' + '已开班' + '</span>';
                    }
                    else if(v == 2) {
                        return '未开班';
                    }
            	}
            },
            width: 70
        }, {
            header: '发布状态',
            dataIndex: 'tc.publish_State',
            width: 70,
            renderer: function(value, meta, record){
                if(value==2){
                	return '<span style="color:red;">' + '未发布' + '</span>';
                 }else if(value==1){
                	 return '<span style="color:green;">' + '已发布' + '</span>';
                 }
              }
        },{
            header: '报名状态',
            dataIndex: 'tc.signUp_State',
            renderer: function(v, meta, record){
            	if(record.get("tc.publish_State") == 2){
            		return '<span style="color:red;">' + '未开始' + '</span>';
            	}if(record.get("tc.publish_State") == 1 && (record.get("tc.open_State") == 1||record.get("tc.open_State") == 3)){
            		return '<span style="color:red;">' + '报名结束' + '</span>';
            	}else{
            		if (v == 2) {
                        return '<span style="color:red;">' + '未开始' + '</span>';
                    }
                    else if(v == 1) {
                        return '<span style="color:green;">' + '正在报名' + '</span>';
                    }
                    else if(v == 3) {
                        return '<span style="color:red;">' + '报名结束' + '</span>';
                    }
            	}
            },
            width: 70
        }];
        me.store = Ext.create('PJ.' + prototype + '.registrationmanagement.List', {
            isLoad: false
        });
        me.loadType = gj_onlineLearning_constant.loadType;
        me.callParent(arguments);
    },
    /**
     * 报名审核
     */
    onApplicationAuditClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
        if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		Ext.create('AM.default.DefaultWindowView', {
            title: "报名审核",
            height:510,
            width: 1055,
            grid: me,
			clickSource:1,
            classId: record[0].get("classId"),
            openState: record[0].get("tc.open_State"),
            items: [{
                xtype: 'applicationAuditList'
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
	/**
	 * 报名调整
	 */
	onRegistrationAdjustmentClick: function(){
    	var me = this;
        var records = me.getSelectionModel().getSelection();
    	if(records.length > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '只允许操作一条数据！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
    		return;
    	}
    	/*
        if (records[0].get("tc.open_State") ==3 || records[0].get("tc.publish_State") != 1) {
            Ext.Msg.show({
                title: '提示',
                msg: '只能对已发布且未结班的班级报名调整！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
            return;
        }
        */
		var win = Ext.create('PJ.view.unitregistrationmanagement.SignUpFrame', {
			grid: me,
			title: "代报名",
			width: 1200,
			height: 650,
			classId: records[0].get("classId"),
			openState: records[0].get("tc.open_State"),
			className:records[0].get('tc.class_Name'),
			endDate:records[0].get('tc.end_Date'),
			beginDate:records[0].get('tc.begin_Date'),
			publishState: records[0].get("tc.publish_State"),
			sponsorId:records[0].get("tc.sponsor_Id"),
			sponsorName:records[0].get("tc.sponsor_Name"),
			signUpState:2,
			auditingState:1,
			clickSource:1
		}).show();
    },
    /**
     * 学员心得下载
     */
    onExperienceIcoClick: function(){
    	var me = this;
    	var records = me.getSelectionModel().getSelection();
    	if(records.length > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '只允许操作一条数据！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
    		return;
    	}
    	Ext.create('AM.default.DefaultWindowView', {
    		title: "学员心得下载",
    		grid: me,
    		classId:records[0].get("classId"),
    		className:records[0].get("tc.class_Name"),
			clickSource:1,
			width: 530,
			height: 350,
			items: [{
				xtype: 'ViewExperienceList'
			}]
		}).show();
    },
    /**
     * 导出
     */
    onExportClick: function(num){
    	var me = this;
    	var store = me.getStore();
    	var params=store.proxy.extraParams;
    	var records = me.getSelectionModel().getSelection();
    	if(num == 1){
    		var href=store.exportUrl + '?auditingState=1&clickSource=1';
    		for(var param in params){
    			if(params[param] === undefined){
    				href+="&"+param+"=";
    			}else{
    				href+="&"+param+"="+params[param];
    			}
    		}
    		href+="&expState="+num+"&searchSignUpState=1&searchSignUpState=5";
    		href = encodeURI(href);
    		var atag = Ext.get("exportResume");
    		atag.set({
    			"href": href
    		});
    		atag.dom.click();		
    	}else{
    		var href=store.exportUrl + '?auditingState=1&clickSource=2';
    		for(var i = 0;i<records.length;i++){
    			href += "&searchClassIds=" + records[i].get("classId");
        	}
    		href+="&expState="+num+"&searchSignUpState=1&searchSignUpState=5";
    		href = encodeURI(href);
    		var atag = Ext.get("exportResume");
    		atag.set({
    			"href": href
    		});
    		atag.dom.click();
    	}
    },
    //查看报名通过人员
    onViewSignupStatus:function(){
    	var me = this;
    	var records = me.getSelectionModel().getSelection();
    	var auditingState=new Array();
		auditingState.push(1);
		auditingState.push(5);
    	win = Ext.create('PJ.view.registrationmanagement.ViewSignupStatusFrame',{
    		title: "查看报名通过人员",
    		grid: me,
    		classId:records[0].get("classId"),
    		className:records[0].get("tc.class_Name"),
//    		ministrieName:records[0].get("t.ministrieName"),查看报名
    		beginDate: records[0].get("tc.begin_Date"),
    		endDate: records[0].get("tc.end_Date"),
			clickSource:1,
			auditingState:auditingState,
    		openState: records[0].get("tc.open_State")
    	}).show();
    	var actionName = "load";//默认使用非JSONP的加载方法名“load”
        if(gj_onlineLearning_constant.loadType=="jsonp") {
        	actionName= "loadJsonp";
        }
        win.down('form').getForm().doAction(actionName,{
        	url: me.store.configurationUrl,
            params: {
            	classId: records[0].get("classId")//培训班ID
            },
            success:function(form,action){
            	var data = action.response.responseText;
    			var json = gj_onlineLearning_constant.loadType=="ajax" ? Ext.decode(data, true) : action.response;
    			var dateStar = json.data.beginDateStr;//举办时间（开始）
    			var dateEnd = json.data.endDateStr;//举办时间（截止）
    			var form = win.down('form');	 
    			var baseForm = form.getForm();
    			
    			baseForm.findField("className").setValue(json.data.className);//班级名称
//    			baseForm.findField("trainingDeptName").setValue(json.data.ministrieName);//委托部委
    			baseForm.findField("learnTime").setValue(dateStar + ' 至 ' + dateEnd);
            }
        });
    },
    /**
     * 调整名额
     */
    onAdjustTheQuotaClick: function(){
		var me = this;
		var record = this.getSelectionModel().getSelection();
        if(this.getSelectionModel().getCount() > 1){
            Ext.Msg.show({
                title: '提示',
                msg: '操作时只可选中一条记录！',
                icon: Ext.Msg.WARNING,
                buttons: Ext.Msg.OK
            });
        	return;
        }
		Ext.create('AM.default.DefaultWindowView', {
            title: "调整名额",
            height:550,
            width: 650,
            grid: me,
            classId:record[0].get("classId"),
            items: [{
                xtype: 'adjustTheQuotaList'
                    }],
            buttons: [{
                text: '确定',
                scope: this,
                handler: function(button){
                	button.up('window').down('adjustTheQuotaList').sub();
                }
            },{
                text: '关闭',
                scope: this,
                handler: function(button){
                	button.up('window').close();
                }
            }],
            listeners: {
            	close: function(){
            		me.getStore().load();
            	}
            }
        });
	},
    listeners: {
        //点击列表数据时显示按钮事件
    	selectionchange: function(selModel, selected){
    		this.down('#' + this.oldId + "RegistrationAdjustment").setDisabled(selected.length === 0?true:selected[0].get('tc.sponsor_Id')!=$('#selectScope').find("option:selected")[0].value?selected[0].get('tc.sponsor_Id')!=1:false);//报名
    		this.down('#' + this.oldId + "ApplicationAudit").setDisabled(selected.length === 0);//报名审核
    		this.down('#' + this.oldId + "experience").setDisabled(selected.length === 0);//学员心得
    		//this.down('#' + this.oldId + "Export").setDisabled(selected.length === 0);//导出
    		this.down('#' + this.oldId + "ViewSignup").setDisabled(selected.length === 0);//查看报名状态
    		//this.down('#' + this.oldId + "AdjustTheQuota").setDisabled(selected.length === 0);//调整名额
    		this.down('#' + this.oldId + "EntryList").setDisabled(selected.length === 0);//导出培训班报名名单
    	},
        viewready: function(){
        	var me = this;
        	//导出按钮集合
        	var exportMenu = Ext.create('Ext.menu.Menu', {
                items: [{
                    text: '全部报名名单',
	        		iconCls: 'entryListAllIco',
                    listeners: {
                        click: function(btn){
                        	me.onExportClick(1);
                    	}
                    }
                }, {
                    text: '培训班报名名单',
	        		iconCls: 'entryListIco',
	        		disabled: true,
	        		itemId: this.oldId + "EntryList",
                    listeners: {
                    	click: function(btn){
                    		me.onExportClick(2);
                    	}
                    }
                }]
            });
            this.addDocked([{
                dock: 'top',
                xtype: "searchform",
                columnCount: 3,
                fieldDefaults: {
                    xtype: "combo",
                    emptyText: "请选择",
                    editable: false,
                    queryMode: 'local',//'remote',//数据类型
                    valueField: 'value',
                    displayField: 'text',
                    
                    labelAlign: 'right',
                    labelWidth: 80,
                    maxLength: 100
                },
                items: [{
                    xtype: "textfield",
                    fieldLabel: '培训班编号',
                    name: "searchClassNum",
                    emptyText: "请输入培训班编号"
                }, {
                    xtype: "textfield",
                    fieldLabel: "培训班名称",
                    name: "searchClassName",
                    emptyText: "请输入培训班名称"
                }, {
                    xtype: "textfield",
                    fieldLabel: "主办单位",
                    name: "searchSponsorName",
                    emptyText: "请输入主办单位"
                }, {
    				xtype: 'defaultDate',
    				fieldLabel: '开班时间',
    				name: 'searchBeginDate',
    				id: 'searchBankQUSD_',
    				vtype: 'startLessEndDate',
    				startLessEndDate: {
    					targetCmpId: 'searchBankQUED_',
    					isStart: true
    				},
    				emptyText: "请输入开班时间"
    			}, {
    				xtype: 'defaultDate',
    				fieldLabel: '结业时间:',
    				labelSeparator: '',
    				name: 'searchEndDate',
    				id: 'searchBankQUED_',
    				vtype: 'startLessEndDate',
    				vtypeText: '结束时间不能早于开始时间！',
    				startLessEndDate: {
    					targetCmpId: 'searchBankQUSD_',
    					isStart: false
    				},
    				emptyText: "请输入结业时间"
    			},/* {
                    fieldLabel: "审核状态",
                    name: "searchSignUpState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '审核通过'], [2, '审核未通过'], [3, '未审核']]
    				})
                },*/ {
                    fieldLabel: "班级状态",
                    name: "searchOpenState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '已开班'], [2, '未开班'], [3, '已结班']]
    				})
                }, {
                    fieldLabel: "报名状态",
                    name: "searchSignUpState",
                    store: Ext.create("Ext.data.ArrayStore", {
    					fields: ['value', 'text'],
    					data: [[1, '正在报名'], [2, '未开始'], [3, '报名结束']]
    				})
                },{
                	xtype:"combo",
                    fieldLabel: "培训班类型",
                    name: "searchClassType",
                    emptyText: "请选择",
    				labelAlign: 'right',
                	store: Ext.create("Ext.data.ArrayStore", {
                		singleton: true,
                		fields: [{
                			name: 'value',
                			mapping: "dataCode",
                			type: 'string'
                		}, {
                			name: 'text',
                			mapping: "dataName",
                			type: 'string'
                		}],
                		proxy: {
                			type: gj_onlineLearning_constant.loadType,
                			url: this.store.trainingClassTypeUrl + '?typeCode=pxblx',
                			reader: Ext.create('Ext.data.reader.Json', {
                				type: 'json',
                				root: 'data',
                				successProperty: 'success'
                			})
                		},
                		autoLoad: true
                	}),
        			valueField: 'value',
        			displayField: 'text',
        			editable: false,
        			defaultActive: false
                }],
                grid: this
            },{
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [{
                    text: '报名审核',
                    iconCls: 'applicationAuditIco',
                    itemId: this.oldId + "ApplicationAudit",
                    disabled: true,
                    scope: this,
                    handler: this.onApplicationAuditClick
                }, '-', {
                    text: '查看报名通过人员',
                    iconCls: 'applicationAuditIco',
                    itemId: this.oldId + "ViewSignup",
                    disabled: true,
                    scope: this,
                    handler: this.onViewSignupStatus
                }, /*"-",{
                    text: '调整名额',
                    iconCls: 'adjustTheQuotaIco',
                    itemId: this.oldId + "AdjustTheQuota",
                    disabled: true,
                    scope: this,
                    handler: this.onAdjustTheQuotaClick
                }, */'-', {
                    text: '代报名',
                    iconCls: 'registrationAdjustmentIco',
                    itemId: this.oldId + "RegistrationAdjustment",
                    disabled: true,
                    scope: this,
                    handler: this.onRegistrationAdjustmentClick
                },'-', {
                    text: '学员心得下载',
                    iconCls: 'experienceIco',
                    itemId: this.oldId + "experience",
                    disabled: true,
                    scope: this,
                    handler: this.onExperienceIcoClick
                },'-',{
                    text: '导出',
                	xtype: 'button',
                    cls: 'floater',
                    textAlign: 'right',
                    arrowAlign: 'right',
                    itemId: this.oldId + 'Export',
                    enableToggle: true,
                    iconAlign: 'left',
                    iconCls: 'deriveIco',
                    pressedCls: 'x-btn-focus',
                    menuActiveCls: 'x-btn-menu-active',
                    menu: exportMenu
				}, "->", "->", this.countSelectPanel]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
            var store = this.store;
            var params = store.proxy.extraParams;
            var newParams = {};
            Ext.apply(params, newParams);
            store.isLoad = true;
            store.load();
        },
        afterrender: function(){
            this.loadMask = new Ext.LoadMask(this, {
                msg: "正在加载中,请稍后...."
            });
        }
    }
});
